package com.azh.server.tables;

import com.azh.server.datam.DataManager;
import com.azh.server.parser.statement.Begin;
import com.azh.server.parser.statement.Create;
import com.azh.server.parser.statement.Delete;
import com.azh.server.parser.statement.Insert;
import com.azh.server.parser.statement.Select;
import com.azh.server.parser.statement.Update;
import com.azh.server.util.Parser;
import com.azh.server.vm.VersionManager;

/**
 * @author zhaozhenhang <zhaozhenhang@kuaishou.com>
 * Created on 2022-05-01
 */
public interface TableManager {

    public BeginRes begin(Begin begin);

    public byte[] commit(long txId) throws Exception;

    public byte[] abort(long txId);

    public byte[] show(long txId);

    public byte[] create(long txId, Create create) throws Exception;

    public byte[] insert(long txId, Insert insert) throws Exception;

    public byte[] read(long txId, Select select) throws Exception;

    public byte[] update(long txId, Update update) throws Exception;

    public byte[] delete(long txId, Delete delete) throws Exception;

    public static TableManager create(String path, VersionManager vm, DataManager dm) {
        Bootstarter starter = Bootstarter.create(path);
        starter.update(Parser.longToByte(0));
        return new TableManagerImpl(vm, dm, starter);
    }

    public static TableManager open(String path, VersionManager vm, DataManager dm) {
        Bootstarter starter = Bootstarter.open(path);
        return new TableManagerImpl(vm, dm, starter);
    }
}
